package com.leff.pvz;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import android.content.Context;
import android.util.Log;

public class ResourceLibrary implements Constants {

	private static ResourceLibrary instance = new ResourceLibrary();
	public static ResourceLibrary getInstance() {
		return instance;
	}
	
	private TextureSheet1 mSheet1;
	
	private BitmapTextureAtlas mTexture1;
	
	public GameSceneLibrary GameScene;
	
	private ResourceLibrary() {
	}
	
	public void initialize(Engine E, Context C) {
		
		Log.v(TAG,"Initializing Resource Library...");
		
		initTextures();
		
		E.getTextureManager().loadTextures(
				mTexture1
			);
		E.getFontManager().loadFonts(
			);
		
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
		
		mSheet1 = new TextureSheet1(C);
		
		GameScene = new GameSceneLibrary(C);
		
//		ObjectFactory.loadFactory(mCoinSheet1, mCoinSheet2, mCoinSheet3, C);
		
	}
	
	private void initTextures() {
		
		int texSize = 512;
		
		mTexture1 = new BitmapTextureAtlas(texSize, texSize, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
	}
	
	private class TextureSheet1 {
		
		TextureRegion testImage;
		
		public TextureSheet1(Context C) {
			
			int x = 0;
			int y = 0;
			
			testImage = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mTexture1, C, "rage_fu.png", x, y);
		}
	}
	
	public class GameSceneLibrary {
		
		public Sprite testSprite;
		
		public GameSceneLibrary(Context C) {
			
			testSprite = new Sprite(0, 0, mSheet1.testImage);
		}
	}
}
